package com.gton.controller;


import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.gton.io.Resp;
import com.gton.rpcbyfegin.OpenFeignRPCUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

/**
 * third-party-service开始
 *
 * @author 郭童
 * @since 2023-06-27 22:20:10
 */
@RestController
@RequestMapping("hello")
@Api(tags = "start third-party-service")
@Primary
public class HelloController {
    /**
     * 服务对象
     */
    @Autowired
    private OpenFeignRPCUserService openFeignRPCUserService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryOne/{id}")
    public Resp<Object> selectOne(@PathVariable("id") String id) {
        return Resp.Ok(this.openFeignRPCUserService.selectOne(id));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getOne2/{id}")
    public Resp<Object> getOne(@PathVariable("id") String id) {
        return Resp.Ok("来自third-party-service" + id);
    }


    @RequestMapping(value = "isLogin", method = RequestMethod.GET)
    public SaResult isLogin() {
        return SaResult.ok("是否登录：" + StpUtil.isLogin());
    }

    @RequestMapping(value = "tokenInfo", method = RequestMethod.GET)
    public SaResult tokenInfo() {
        return SaResult.data(StpUtil.getTokenInfo());
    }

    @RequestMapping(value = "logout", method = RequestMethod.GET)
    public SaResult logout() {
        StpUtil.logout();
        return SaResult.ok();
    }

}

